$(document).ready(function() {
	$(".addForm").validate({
		onfocusout: function(element) {
			$(element).valid();
		},
		rules: {
			address: "required",
			fax: "required",
			year_production: "required",
			link_phone: "required",
			phone: {
				required: true,
				isPhone: true,
			},
			link_name: "required",
			introduction: "required"
		},
		messages: {
			address: "请输入地址",
			fax: "请输入传真号码",
			year_production: "请输入年生产值",
			link_phone: "请输入联系人号码",
			phone: {
				required: "请输入联系号码",
				isPhone: "请正确填写您的联系号码"
			},
			link_name: "请输入联系人名称",
			introduction: "请输入简介"
		}
	});
	$('.addHref').click(function() { //jquery的点击事件 
		$(".croppedfile").empty();
		$(".croppedfile").slideUp(200);
		$(".span12").slideUp(200);
		$('.imgcontainer').slideDown(200); //将隐藏的窗口div显示出来
	});
	var img;
	var options = {
		thumbBox: '.thumbBox',
		spinner: '.spinner',
		imgSrc: 'images/avatar.png'
	}
	var cropper = $('.imageBox').cropbox(options);
	$('#upload-file').on('change', function() {
		var reader = new FileReader();
		reader.onload = function(e) {
			options.imgSrc = e.target.result;
			cropper = $('.imageBox').cropbox(options);
		}
		reader.readAsDataURL(this.files[0]);
		this.files = [];
	})
	$('#btnCrop').on('click', function() {
		img = cropper.getDataURL();
		$('.cropped').html('');
		$('.cropped').append('<img src="' + img + '" align="absmiddle" style="width:100px;height:100px;margin-top:4px;box-shadow:0px 0px 12px #7E7E7E;"><p>100px*100px</p>');
		$('.cropped').append('<img src="' + img + '" align="absmiddle" style="width:200px;height:200px;margin-top:4px;box-shadow:0px 0px 12px #7E7E7E;"><p>200px*200px</p>');
	})
	$('#btnZoomIn').on('click', function() {
		cropper.zoomIn();
	})
	$('#btnZoomOut').on('click', function() {
		cropper.zoomOut();
	})
	$('.closeimgcontainer').click(function() {
		$('.imgcontainer').slideUp(200); //将显示的窗口隐藏起来 
		$(".croppedfile").empty();
		$('.croppedfile').append('<img src="' + img + '" align="absmiddle" style="width:150px;height:150px;margin-top:4px;box-shadow:0px 0px 12px #7E7E7E;"><p style="margin-left:48px;color: #898989;font-size: 10px;">预览图</p>');
		$(".croppedfile").slideDown(200);
		$(".span12").slideDown(200);
	});
})